package net.sourceforge.ehep.gui;

import net.sourceforge.ehep.gui.HexEditorControl.AppendDataCommand;

import org.eclipse.swt.widgets.Composite;

public class WatermarkEditControl {
	private final Composite parent;
	private int appValue;
	
	/**
	 * Constructor
	 * @param parent
	 */
	public WatermarkEditControl(final Composite parent){
		this.parent = parent;
		appValue = 67;
	}
	
	/**
	 * Constructor
	 * @param parent
	 */
	public WatermarkEditControl(){
		this.parent = null;
		appValue = 67;
	}
	
	/**
	 * Created by: Sophia Ghins
	 * set value to append
	 * Date: 05/17/09
	 */
	public void setValue(int val){
		this.appValue = val;
	}
	
	/**
	 * Created by: Sophia Ghins
	 * get the value
	 * Date: 05/17/09
	 */
	public int getValue(){
		return this.appValue;
	}
	
	/**
	 * Created by: Sophia Ghins
	 * method to add watermark (signature)to the current open file
	 * Date: 05/13/09
	 */
	public void addWatermark(HexEditorControl editor){
		int size, row, col;
		boolean refreshview;
		
		row = editor.getHexTable().getItemCount();
		col = editor.getHexTable().getItem(row-1).getItemSize();
		size = 1;
		refreshview = true;
		
		editor.appendData(size, appValue, row - 1, col, refreshview);
	}
	
	/**
	 * Created by: Sophia Ghins
	 * method to remove watermark (signature)from the current open file
	 * (currently just removes the last cell from the table)
	 * Date: 05/13/09
	 */
	public void deleteWatermark(HexEditorControl editor){
		int size, row, col;
		boolean refreshview, verify;
		
		row = editor.getHexTable().getItemCount();
		col = editor.getHexTable().getItem(row-1).getItemSize();
		size = 1;
		refreshview = true;
		
		//if(verifyWatermark()){
			editor.delete(row - 1, col - 1, size);
		//}else{
			//sorry no watermark signature found
		//}
	}
	
	/**
	 * Created by: Sophia Ghins
	 * method to verify that a file has been watermarked (already has signature)
	 * (currenty verifying that the last cell in the hex table is equal to ASCII value 'C')
	 * Date: 05/13/09
	 */
	public boolean verifyWatermark(HexEditorControl editor){
		int row, col;
		String data;
		boolean chk;
				
		data = "C";
		row = editor.getHexTable().getItemCount();
		col = editor.getHexTable().getItem(row-1).getItemSize();
		chk = editor.getHexTable().verifyData(data, row - 1);
//		TODO: compare the value of this item with value while debugging		
		if(chk){
			System.out.println("Success");
			return true;
		}
		return false;
	}
	
	
	
	
}
